/**
 * create by ck on 2016/7/26.
 */

var schoolId;       //学校ID
$(document).ready(function(){
    var serverId   = xhTool.getQuery('iUserId');
    var DataGrid2  = new DataGridEvent();
    var schoolList = $('#SchoolList');
    var techList   = $('#TeacherList');
    $('.xh-datagrid-toolbar').parseToolbar();
    schoolList.initDataGrid(baseUrl + 'School/getDgData');
    DataGrid.onLoadSuccess = function(data){
        schoolId = data['rows'][0].iSchoolId;
        techList.initDataGrid(baseUrl + 'School/getUserDgData', {"queryParams": {"iUserType": 4, "iSchoolId": data['rows'][0].iSchoolId}}, DataGrid2)
            .datagrid('getPanel').panel('setTitle', '教师列表（' + data['rows'][0].sSchoolName + '）');
    };
    DataGrid.onClickRow = function(rowIndex, rowData){
        schoolId = rowData.iSchoolId;//记录学校ID
        techList.addDataGridParams({"iUserType": 4, "iSchoolId": rowData.iSchoolId})
            .datagrid('getPanel').panel('setTitle', '教师列表（' + rowData.sSchoolName + '）');
    };
    $(window.top.document).find('#bt_modal_confirm').click(function(){
        var teacherIds = techList.getDataGridSelectedFields('iUserId');
        $.post(baseUrl + 'User/contactServerTeacher', {iUserId: serverId, sTeacherIds: teacherIds}, function(result){
            window.top.xhTop.showMessage(result);
        });
    });
});